package cn.dyw.cloudmusic.utils;

import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;
import okio.BufferedSource;

import java.io.IOException;
import java.nio.charset.Charset;

public class OkHttpUtils {

    public static String stringBody(Response response) {
        ResponseBody body = response.body();
        BufferedSource source = body.source();
        try {
            // request the entire body.
            source.request(Long.MAX_VALUE);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Buffer buffer = source.buffer();
        String result = buffer.clone().readString(Charset.forName("UTF-8"));
        return result;
    }
}
